package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	router := gin.Default()

	router.GET("/setcookie", func(c *gin.Context) {
		c.SetCookie("username", "john_doe", 3600, "/", "localhost", false, true)
		c.String(http.StatusOK, "Cookie设置成功！")
	})

	router.GET("/getcookie", func(c *gin.Context) {
		username, err := c.Cookie("username")
		if err != nil {
			c.String(http.StatusNotFound, "未找到Cookie")
			return
		}
		c.String(http.StatusOK, "Cookie的值为：%s\n", username)

	})

	router.Run(":8080")
}
